<?
layout("/inc/win_layout.html",{title:sysTitle}){}
    ?>

<div class="page-content">
		
		<div class="row mbl" >
			<div style="height: 120px;">
				已选择：
				  <div id="menuButtion" style="padding-left: 4%;overflow:auto;height: 100px;"></div>
			</div>
		
			<div class="col-lg-6" style="padding-top: 10px;">
				<div class="input-group input-group-sm mbs">
					<span class="input-group-btn">
						<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
		                    <option value="-1">筛选项&nbsp;<span class="caret"></span></option>
		                    <option value="username">用户名</option>
		                    <option value="nickname">昵称</option>
		                    <option value="telephone">手机号</option>
                    	</select>
                   </span> 
                    	<input id="text" type="text" placeholder="请输入关键词..." class="form-control" /><span
						class="input-group-btn"><button type="button"
							data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
					</span>
				</div>
			</div>
			<div class="col-lg-6">
				<div class="tb-group-actions pull-right">
					<!-- <span >当前已选择<span id="Xuannum">0</span>条记录:</span> 
					<button class="btn btn-sm btn-primary" onclick="delePiLiang()">
						<i class="fa fa-check"></i>&nbsp; 删除多项
					</button>   -->
				</div>
			</div>
		</div>
		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th ><input type="checkbox"></th>
					<th >序号</th>
					<th >用户名</th>
					<th >昵称</th>
					<th >部门</th>
					<th >手机号</th>
					<th >地址</th>
					<th >邮箱</th>
				</tr>
			</thead>
			<tbody id="findUser">
			
			</tbody>
		</table>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>
<script type="text/javascript">
	var roleid = window.parent.getAdduid();
	var curr;
	
	$(function()  {
		queryUser(1);
		save();
	});
	function get() {
		queryUser(curr);
	}
	function queryUser(curr){
		$.ajax({
			type : "post",
			url : "knowledgeEditDataRoleQueryUser.do",
			dataType : "json",
			data :{
				"id" : roleid,
				page : curr || 1,
				queryParams:$("#queryParams").val(),
        		text:$("#text").val()
			},
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(res){
				//alert(JSON.stringify(res));
				var str = "";
				$("#findUser").html("");

				for ( var i = 0; i < res.length; i++) {
					str += "<tr><td>"
           		 			+"<input type='checkbox' name='checkall' value='"+res[i].id+"'/>"
					 		+"</td><td>" 
							+(i + 1)
							+ "</td><td> <label id=>"
							+ res[i].name
							+ "</label></td><td><label >"
							+ res[i].nickname
							+ "</label></td><td><label >"
							+ res[i].partment
							+ "</label></td><td><label >"
							+ res[i].telephone
							+ "</label></td><td><label >"
							+ res[i].address
							+ "</label></td><td><label >"
							+ res[i].email
							+ "</label></td>"
							+ "</tr>";
				}
				$("#findUser").append(str);
					laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res[0].pagination, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: curr || 1,
					last: res[0].pagination,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							queryUser(obj.curr);
							 curr = obj.curr;
						}
					}
				});
			}
		});
	
	}

	//删除用户
	function deleteUserRole(userRoleId) {
	if (confirm("是否确认删除！！")){
		$.ajax({
			type : "post",
			data : {
				"id" : userRoleId
			},
			url : "knowledgeEditDataDeleteUser.do",
			dataType : "json",
			traditional : true,
			beforeSend : function(XMLHttpRequest) {},
			success : function(data){
				save();
				layer.msg('删除成功！');
			},
		});
	}
	}
	//删除全部用户
	function deleteAll() {
	if (confirm("是否确认删除全部！！")){
		$.ajax({
			type : "post",
			data : {
				"id" : roleid
			},
			url : "knowledgeEditDataDeleteAllUser.do",
			dataType : "json",
			traditional : true,
			beforeSend : function(XMLHttpRequest) {},
			success : function(data){
				save();
				layer.msg('删除成功！');
			},
		});
	}
	}
	
	//按钮详情
	function button(buttonid){
		buttionId=buttonid;
		layer.open({
			type : 2,
			area : [ '500px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title : "按键详情",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '关闭' ],
			content : [ "knowledge-edit-data-querymenubutton.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = window.parent.window[window.name].window['layui-layer-iframe'+index];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	function save(){
	
		var value=[];
		$("input[name='checkall']:checked").each(function(){
			value.push($(this).val());
		});
		$.ajax({
			type : "post",
			data : {
				"roleId" : value,
				"id" : roleid,
			},
			url : "knowledgeEditDataAddUser.do",
			dataType : "json",
			traditional : true,
			beforeSend : function(XMLHttpRequest) {},
			success : function(data){
				//alert(JSON.stringify(data));
           		var str = "";
				$("#menuButtion").html("");
				for ( var i = 0; i < data.length; i++) {
					str += "<input  class='btn btn-blue btn-square' style='padding-top: -10px; margin-top: 10px; margin-right: 0px;' onclick='querybutton("+data[i].id+")' type='button' value="+data[i].name+" />"
						+ "<a  href='javascript:deleteUserRole("
						+ data[i].userRoleId
						+ ");' style='font-size: 18px; margin-right: 5px;'><i"
						+"style='margin-left: -30px;' class='fa fa-times-circle-o'></i></a>";
				}
				if("" != str){
					str +="<input class='btn btn-blue btn-square' style='padding-top: -10px; margin-top: 10px; margin-right: 0px;' onclick='deleteAll()' type='button' value='删除全部' />";
				}
				$("#menuButtion").append(str);
				queryUser(1);
			},
		});
	}
</script>
